<template>
  <div class="dashboard-editor-container">
    <el-row style="text-align: center;font-size: 18px;font-weight: 700;">近期用户交易明细</el-row>

    <panel-group @handleSetLineChartData="handleSetLineChartData" />

    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;border-radius:10px;">

      <line-chart :chart-data="lineChartData" />
    </el-row>

    <el-row :gutter="25">
      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper card">
          <pie-chart :chart-data="pieChartData"/>
          <span>商店热销款</span>
        </div>
      </el-col>

      <el-col :xs="24" :sm="24" :lg="12">
        <div class="chart-wrapper card">
          <pie-chart :chart-data="pieChartData1"/>
          <span>用户转化率</span>
        </div>
      </el-col>
    </el-row>


    <el-row :gutter="8">
      <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 18}" :lg="{span: 18}" :xl="{span: 18}">
        <div class="chart-wrapper card">
          <bar-chart />
          <span>一周内用户活跃量</span>
        </div>
      </el-col>
      <el-col :xs="{span: 24}" :sm="{span: 12}" :md="{span: 6}" :lg="{span: 6}" :xl="{span: 6}" style="margin-bottom:30px;">
        <box-card />
      </el-col>
    </el-row>

  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'
import RaddarChart from './components/RaddarChart'
import PieChart from './components/PieChart'
import BarChart from './components/BarChart'
import TransactionTable from './components/TransactionTable'
import TodoList from './components/TodoList'
import BoxCard from './components/BoxCard'
import axios from 'axios'

var lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145],
    expectedName:"浏览人数",
    actualName:"下单人数"
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130],
    expectedName:"收到消息",
    actualName:"回复消息"
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130],
    expectedName:"总交易额",
    actualName:"预期利润"
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130],
    expectedName:"订单总数",
    actualName:"已处理数"
  }
}

var pieChartData={
  hotSale:{
    dataName:['韦德之道 幻影3', '驭帅15', '绝影CRC', '惟吾Pro', '韦德之道全城8','其他'],
    //----商品购买人数
    data:[
      { value: 320, name: '韦德之道 幻影3' },
      { value: 240, name: '驭帅15' },
      { value: 149, name: '绝影CRC' },
      { value: 100, name: '惟吾Pro' },
      { value: 59, name: '韦德之道全城8' },
      { value: 44, name: '其他' }
    ]
  },
  commodity:{
    dataName:['韦德之道幻影3', '驭帅15', '绝影CRC', '惟吾Pro', '韦德之道全城8','其他'],
    //----用户转换率：购买人数/浏览人数
    data:[
      { value: 0.55, name: '韦德之道幻影3' },
      { value: 0.20, name: '驭帅15' },
      { value: 0.10, name: '绝影CRC' },
      { value: 0.08, name: '惟吾Pro' },
      { value: 0.04, name: '韦德之道全城8' },
      { value: 0.03, name: '其他' }
    ]
  }
}

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    TransactionTable,
    TodoList,
    BoxCard
  },
  data() {
    return {
      lineChartData: lineChartData.newVisitis,
      pieChartData: pieChartData.hotSale,
      pieChartData1: pieChartData.commodity
    }
  },
  methods: {
    handleSetLineChartData(type) {
      console.log(type);
      this.lineChartData = lineChartData[type]
    }
  },
  created(){
    axios.post('/test',{
      headers:{
        'Content-Type': 'application/json'
      }
    }).then(res=>{
      console.log("session",res);
    })
    .catch(error=>{
      console.log("error: "+error);
    })
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;


  .chart-wrapper {
    background: #fff;
    padding: 13px 16px;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height:100%;
  }

  .card{
    border-radius:10px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
